
# 特性属性的示例

class Student:
    def __init__(self, s):
        self.__score = s
    def get_score(self):
        return self.__score
    def set_score(self, s):
        if s < 0 or s > 100:
            raise ValueError('分数错误')
        self.__score = s
    # 创建一个特性属性，指定对此属性取值使用get_score方法
    #              对此属性赋值使用set_score方法
    score = property(get_score, set_score)

stu1 = Student(59)
# 安全
# print(stu1.get_score())
# stu1.set_score(90)
# print(stu1.get_score())

# 不安全
print(stu1.score)  # 调用 stu1.get_score()
stu1.score = 90  # 调用 stu1.set_score(9000)
print(stu1.score)